//
//  PopTransitionAnimation.m
//  29-TransitionAnimation
//
//  Created by dllo on 16/8/23.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "PopTransitionAnimation.h"
#import "SecondViewController.h"
#import "ViewController.h"
@implementation PopTransitionAnimation
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
    return 0.5f;
}

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
    SecondViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    ViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
    // 获取转场View
    UIView *containerView = [transitionContext containerView];
    [containerView addSubview:toVC.view];
    toVC.fromVCImageView.hidden = YES;
    UIView *snapView = [fromVC.toVCImageView snapshotViewAfterScreenUpdates:NO];
    
    snapView.frame = fromVC.toVCImageView.frame;
    
    [containerView addSubview:snapView];
    
    [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
//        [containerView layoutIfNeeded];
        snapView.frame = toVC.fromVCImageView.frame;
    } completion:^(BOOL finished) {
        toVC.fromVCImageView.hidden = NO;
        [snapView removeFromSuperview];
        [transitionContext completeTransition:YES];
    }];
    
    
    
}

@end
